package top.littleze.aiattendance.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.littleze.aiattendance.dao.AttendanceUserEntityMapper;
import top.littleze.aiattendance.entity.AttendanceUserEntity;
import top.littleze.aiattendance.service.UserService;
import top.littleze.aiattendance.utils.page.Reply;

/**
 * @Author ZhaoGengze
 * @Date 2021/7/3 12:12
 */

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    AttendanceUserEntityMapper userEntityMapper;

    /**
     * 登录
     * @param userId
     * @param password
     */
    @Override
    public Reply login(String userId, String password) {
        log.info("userId: {},  password: {}", userId, password);

        // 查数据库
        AttendanceUserEntity userEntity = userEntityMapper.queryLogin(userId, password);
        // 验证成功
        if (userEntity != null) {
            int role = userEntity.getRole();

            // 根据角色跳转到相应界面
            if (role == 0) {
                return Reply.success(userEntity, 0);
            } else if (role == 1) {
                return Reply.success(userEntity, 1);
            } else if (role == 2) {
                return Reply.success(userEntity, 2);
            }
        }
        return Reply.failuer(1, "用户名或密码错误");
    }
}
